'use strict';
const db = uniCloud.database();
exports.main = async (event, context) => {
	//event为客户端上传的参数
	const {
		action
	} = event
	let res = {}
	if (action === 'get') {
		res = await db.collection('user').get()
	} else if (action === 'add') {
		const {
			id,
			password
		} = event
		res = await db.collection('user').add({
			id,
			password
		})
	} else if (action === 'delete') {
		const {
			id
		} = event
		res = await db.collection('user').doc(id).remove()
	} else if (action === 'getOne') {
		const {
			id
		} = event
		res = await db.collection('user').where({
			id
		}).get()
	} else if (action === 'update') {
		const {
			form
		} = event
		res = await db.collection('user').where({
			_id: form._id
		}).update({
			name: form.name
		})
	}
	//返回数据给客户端
	return res
};


